package com.hqyj.crmdemo.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hqyj.crmdemo.entity.CustmerName;
import com.hqyj.crmdemo.entity.Orders;
import com.hqyj.crmdemo.entity.RestResult;
import com.hqyj.crmdemo.entity.SaleChance;
import com.hqyj.crmdemo.mapper.OrdersMapper;
import com.hqyj.crmdemo.service.IOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 何万林
 * @since 2022-10-17
 */
@RestController
@RequestMapping("/orders")
@CrossOrigin
public class OrdersController {

    @Autowired
    IOrdersService service;

    @RequestMapping(value = "/list",method = RequestMethod.POST)
    public RestResult<Orders> queryAll() {
        List<Orders> orders = service.queryAll();
        return RestResult.ok(orders);
    }

    @RequestMapping(value = "/page", method = RequestMethod.POST)
    public RestResult<Orders> queryPage(@RequestParam(defaultValue = "1")@PathVariable("page") Integer page,
                                            @RequestParam(defaultValue = "5")@PathVariable("size") Integer size){
        Page<Orders> page1 = service.page(new Page<>(page, size));
        Long total = page1.getTotal();
        return  RestResult.ok(page1.getRecords(),total);
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public RestResult<SaleChance> add(Orders orders) {
        Boolean aBoolean = service.add(orders);
        if (aBoolean) {
            return RestResult.ok("success");
        }else{
            return RestResult.ok("false");
        }
    }


}
